﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject.Web.Mvc;
using Ninject;
using Ninject.Extensions.Xml;
using Azure.Toolkit;

namespace AzureFacebook.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : NinjectHttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

        }

        protected override void OnApplicationStarted()
        {
            RegisterRoutes(RouteTable.Routes);
            //RegisterAllControllersIn("AzureFacebook.Web");
            base.OnApplicationStarted();
        }


        protected override IKernel CreateKernel()
        {
            var settings = new NinjectSettings { LoadExtensions = false };

            //IKernel kernel = new StandardKernel(settings, new XmlExtensionModule());
            //kernel.Load("modules.xml");

            IKernel kernel = new StandardKernel();
            kernel.Bind<AzureFacebook.Domain.ICommentService>().To<AzureFacebook.Domain.CommentService>();


            kernel.Load(typeof(DataContextProvider).Assembly);

            return kernel;
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
        }
    }
}